<?php

/**
 * This is the model class for table "{{states}}".
 *
 * The followings are the available columns in table '{{states}}':
 * @property string $state_code
 * @property string $state_name
 * @property integer $is_active
 * @property integer $active_lender
 * @property integer $active_borrower
 * @property integer $active_broker
 */
class States extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return States the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{states}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('state_name, state_code', 'required'),
            // make sure state_code is unique
            array('state_code', 'unique'),
			array('is_active, active_lender, active_borrower, active_broker', 'numerical', 'integerOnly'=>true),
			array('state_code, state_name', 'length', 'max'=>100),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('state_code, state_name, is_active, active_lender, active_borrower, active_broker', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'state_code' => 'State Code',
			'state_name' => 'State Name',
			'is_active' => 'Is Active',
			'active_lender' => 'Active Lender',
			'active_borrower' => 'Active Borrower',
			'active_broker' => 'Active Broker',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('state_code',$this->state_code,true);
		$criteria->compare('state_name',$this->state_name,true);
		$criteria->compare('is_active',$this->is_active);
		$criteria->compare('active_lender',$this->active_lender);
		$criteria->compare('active_borrower',$this->active_borrower);
		$criteria->compare('active_broker',$this->active_broker);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}